package com.rabbitmq.demo.controller;

import com.rabbitmq.demo.conf.PublishSubscribeConfig;
import com.rabbitmq.demo.conf.RoutingQueueConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 路由模式生产者
 *
 * @Author yi.cheng
 * @Date 2023-7-13 09:20
 **/
@RestController
public class RoutingQueueProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/api/routing")
    public String sendRoutingQueueMsg(@RequestParam String message,@RequestParam String routingKey){
        rabbitTemplate.convertAndSend(RoutingQueueConfig.ROUTING_DIRECT_EXCHANGE, routingKey,message.getBytes());
        return "ok";
    }
}
